import { ref } from 'vue';
import { onMounted } from 'vue';

export default function useSliderCaptcha({
  domId,
  onSuccess,
  onFail
}: {
  domId: string;
  onSuccess: (arr: any[]) => void;
  onFail: () => void;
}) {
  let captcha = ref(null);

  onMounted(async () => {
    await Promise.all([
      import('@/vendor/SliderCaptcha/slidercaptcha.min.css'),
      // @ts-ignore
      import('@/vendor/SliderCaptcha/longbow.slidercaptcha.min.js')
    ]);
    captcha.value = (window as any).sliderCaptcha({
      id: domId,
      onSuccess,
      onFail,
      verify() {
        return true;
      }
    });
  });

  return { captcha };
}
